// function foo(params) {
//     //Promise
//     return new Promise()
// }


//传入的这个函数，被称之为executor
// resolve:回调函数，在成功时，回调resolve函数
// reject：回调函数，在失败时，回到reject函数
// const promise  = new Promise((resolve,reject)=>{
//     //  console.log("promise传入的函数被执行了")
//     setTimeout(()=>{
//         if(url === "coderwhy"){
//             let names = ["abc","cba","nba"]
//             resolve()
//         }else {
//             let errMessage = "请求失败,url错误"
//             reject()
//         }
//     },3000)
// })

function requestData(url) {
    return new Promise((resolve,reject)=>{
        //  console.log("promise传入的函数被执行了")
        setTimeout(()=>{
            if(url === "coderwhy"){
                let names = ["abc","cba","nba"]
                resolve()
            }else {
                let errMessage = "请求失败,url错误"
                reject()
            }
        },3000)
    })
    
}

const promise = requestData()
promise.then(()=>{
    console.log("")
}).catch(()=>{
    console.log("")
})